package action.ManagerAction;

import com.alibaba.fastjson.JSON;
import com.opensymphony.xwork2.ActionSupport;
import common.Pagination;
import entity.CroFee;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import service.CroFeeService;
import vo.CroFeeVo;

import java.util.List;

/**
 * Created by Administrator on 2017/5/12 0012.
 */

public class CroFeeAction extends ActionSupport{
    private List<CroFee> crofee ;
    private CroFee upcrofee;
    private String id;
    private String name;
    private String type;
    private double cost;
    private String del_flag;
    private String successResult;
    private int pageIndex;
    private int pageCount;
    private int pageSize = 10;
    private CroFeeVo croFeeVo;
    private CroFeeVo recroFeeVo;
    private String jsonObject;

    @Autowired
    private CroFeeService croFeeService;




    /*
   * 多属性搜索
   * */
    @RequiresPermissions("user:select")
    public String querylist(){
        Pagination<CroFee> page;
        if(pageIndex==0){
            page=croFeeService.FindUserByProperty(croFeeVo,1,pageSize);
        }else {
            page=croFeeService.FindUserByProperty(croFeeVo,pageIndex,pageSize);
        }
        setPageCount((int) page.getPagesCount());
        setPageIndex((int) page.getCurIndex());
        setRecroFeeVo(croFeeVo);
        jsonObject= JSON.toJSONString(recroFeeVo);
        setCrofee(page.getItems());
        return SUCCESS;
    }


    /*
   * 分页展示费用信息
   * */
    @RequiresPermissions("user:select")
    public String showdetail(){
        Pagination<CroFee> page;
        if(pageIndex==0){
            page=croFeeService.findAllUser(1,pageSize);
        }else{
            page=croFeeService.findAllUser(pageIndex,pageSize);
        }
        setPageCount((int) page.getPagesCount());
        setPageIndex((int) page.getCurIndex());
        setCrofee(page.getItems());
        return SUCCESS;
    }


    @RequiresPermissions("user:delete")
    /*删除操作*/
    public String deleFee(){
        if(croFeeService.delFeeById(id)){
            successResult = "删除成功";
        }else {
            successResult = "删除失败";
        }
        return SUCCESS;

    }


    @RequiresPermissions("user:write")
    /*添加操作*/
    public String addFee(){
        CroFee croFee = new CroFee();
        croFee.setCost(cost);
        croFee.setName(name);
        croFee.setType(type);
        if(croFeeService.addFee(croFee)){
            successResult = "添加成功";
        }else {
            successResult = "添加失败";
        }
        return SUCCESS;
    }


    @RequiresPermissions("user:update")
    /*修改操作*/
    public String updateCoupons(){
        CroFee croFee = croFeeService.FindFeeById(id);
        croFee.setType(type);
        croFee.setCost(cost);
        croFee.setName(name);
        if(croFeeService.updateFee(croFee)){
            successResult="修改成功";
        }else {
            successResult="修改失败";
        }
        return SUCCESS;
    }

    /*根据id返回费用信息*/
    @RequiresPermissions("user:select")
    public String listFee(){
        upcrofee=croFeeService.FindFeeById(id);
        return "updatefee";
    }
    public CroFee getUpcrofee() {
        return upcrofee;
    }

    public void setUpcrofee(CroFee upcrofee) {
        this.upcrofee = upcrofee;
    }

    public CroFeeVo getRecroFeeVo() {
        return recroFeeVo;
    }

    public void setRecroFeeVo(CroFeeVo recroFeeVo) {
        this.recroFeeVo = recroFeeVo;
    }

    public String getJsonObject() {
        return jsonObject;
    }

    public void setJsonObject(String jsonObject) {
        this.jsonObject = jsonObject;
    }

    public CroFeeVo getCroFeeVo() {
        return croFeeVo;
    }

    public void setCroFeeVo(CroFeeVo croFeeVo) {
        this.croFeeVo = croFeeVo;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageCount() {
        return pageCount;
    }

    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public String getSuccessResult() {
        return successResult;
    }

    public void setSuccessResult(String successResult) {
        this.successResult = successResult;
    }

    public List<CroFee> getCrofee() {
        return crofee;
    }

    public void setCrofee(List<CroFee> crofee) {
        this.crofee = crofee;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    public String getDel_flag() {
        return del_flag;
    }

    public void setDel_flag(String del_flag) {
        this.del_flag = del_flag;
    }

    public CroFeeService getCroFeeService() {
        return croFeeService;
    }

    public void setCroFeeService(CroFeeService croFeeService) {
        this.croFeeService = croFeeService;
    }
}
